package com.dwx.gmall.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwx.gmall.common.result.Result;
import com.dwx.gmall.model.product.SkuInfo;
import com.dwx.gmall.product.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SkuInfoController {

    @Autowired
    SkuInfoService skuInfoService;
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        boolean b=skuInfoService.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    @GetMapping("/list/{page}/{limit}")
    public Result<Page<SkuInfo>> pageSkuInfo(
            @PathVariable("page") Long page,
            @PathVariable("limit") Long limit
    ){
        Page<SkuInfo> skuInfoPage=new Page<>(page,limit);
        skuInfoService.page(skuInfoPage);
        return Result.ok(skuInfoPage);
    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        boolean b=skuInfoService.onSale(skuId);
        return Result.ok();
    }

    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        boolean b=skuInfoService.cancelSale(skuId);
        return Result.ok();
    }
}
